from sklearn.decomposition import PCA
from sklearn.neural_network import MLPClassifier
from sklearn.metrics import precision_score,recall_score,f1_score
import numpy as np

x = np.loadtxt('PEPX.txt', delimiter=',')
y = np.loadtxt('PEPL.txt', delimiter=',')

pca=PCA(0.75)
x=pca.fit_transform(x)

print(pca.explained_variance_)
print(pca.explained_variance_ratio_)


np.random.seed(666)
a = np.random.permutation(len(x))
x = x[a]
y = y[a]

miu = np.mean(x)
sigma = np.std(x)
x = (x - miu) / sigma

num=int(0.6*len(x))
train_x,test_x=np.split(x,[num,])
train_y,test_y=np.split(y,[num,])

nn=MLPClassifier(hidden_layer_sizes=(200,100),max_iter=200)
nn.fit(train_x,train_y)

test_h=nn.predict(test_x)

print(precision_score(test_y,test_h,average='micro'))
print(recall_score(test_y,test_h,average='micro'))
print(f1_score(test_y,test_h,average='micro'))